/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.team1160.breakaway.model;

import java.util.Hashtable;
import java.util.Vector;

/**
 *
 * @author nttoole
 */
public class Model2 {



    public static final String PROPERTY_KICKER_READY     = "kicker.ready";

    public static final String PROPERTY_DRIBBLER_ENABLED = "dribbler.enabled";

    public static final String PROPERTY_LEFT_SPPED  = "left.drive.speed";

    public static final String PROPERTY_RIGHT_SPPED = "right.drive.speed";

    public static final String PROPERTY_ON_TARGET = "on.target";

    public static final String PROPERTY_SEE_TARGET = "see.target";



    protected Hashtable properties;
    protected Vector listeners;


    public Model2()
    {
        init();
    }

    protected void init()
    {
        this.properties = new Hashtable();
        this.listeners  = new Vector();
    }

    public void reset()
    {
        this.properties.put(PROPERTY_KICKER_READY, Boolean.FALSE);

        this.properties.put(PROPERTY_DRIBBLER_ENABLED, Boolean.FALSE);
       
        this.properties.put(PROPERTY_ON_TARGET, Boolean.FALSE);

        this.properties.put(PROPERTY_SEE_TARGET, Boolean.FALSE);

        this.properties.put(this.PROPERTY_LEFT_SPPED, new Integer(0));

        this.properties.put(this.PROPERTY_RIGHT_SPPED, new Integer(0));
    }

    public synchronized void addListener(PropertyChangeListener l)
    {
        if (!this.listeners.contains(l))
        {
            this.listeners.addElement(l);
        }
    }

    public synchronized void removeListener(PropertyChangeListener l)
    {
        if (this.listeners.contains(l))
        {
            this.listeners.removeElement(l);
        }
    }

    public void setProperty(String propertyName, Object value)
    {
        Object oldValue = this.properties.get(propertyName);

        if (oldValue == null && value == null)
            return;

        if (oldValue != null && oldValue.equals(value))
            return;

        this.properties.put(propertyName, value);
        PropertyChangeEvent pce = new PropertyChangeEvent(propertyName,
                                                        oldValue, value);
    }

    public Object getProperty(String propertyName)
    {
        return this.properties.get(propertyName);
    }

    protected synchronized void firePropertyChangeEvent(PropertyChangeEvent pce)
    {
         int size = this.listeners.size();
         for (int i = 0; i < size; ++i)
         {
             ((PropertyChangeListener) this.listeners.elementAt(i)).propertyChanged(pce);
         }
    }

}
